package options.controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import options.view.OptionTabbedDB;

public class OptionTabbedDBListener {
	private OptionTabbedDB db = null;
	
	public OptionTabbedDBListener(OptionTabbedDB db) {
		this.db = db;
		
		this.initialize();
		
		this.db.getButtonSalva().addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				OptionTabbedDBListener.this.save();				
			}
		});
		
		this.db.getButtonRestore().addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				OptionTabbedDBListener.this.initialize();			
			}
		});
		
		this.db.getTxtAddress().addKeyListener(new KeyAdapter() {
			public void keyPressed(java.awt.event.KeyEvent e) {
				if(e.getKeyCode() == KeyEvent.VK_ENTER)
					OptionTabbedDBListener.this.save();
				else
					OptionTabbedDBListener.this.db.setModified(true);
			};
		});
		
		this.db.getCmbProtocolVersion().addKeyListener(this.db.getTxtAddress().getKeyListeners()[0]);
		this.db.getTxtPassword().addKeyListener(this.db.getTxtAddress().getKeyListeners()[0]);
		this.db.getTxtPort().addKeyListener(this.db.getTxtAddress().getKeyListeners()[0]);
		this.db.getTxtUserName().addKeyListener(this.db.getTxtAddress().getKeyListeners()[0]);
	}
	
	private void initialize(){
	}
	
	public void save() {
	}
}
